package com.gome.oa.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.table.DefaultTableModel;

import com.gome.oa.custom.CustomCheckbox;
import com.gome.oa.dialog.FillFormDialog;

/**
*
* @author: tang li
* @date: 2016年8月13日
* @desc: 
*
*/
public class CheckboxListener implements ActionListener {
	
	private FillFormDialog fillFormDialog;
	private DefaultTableModel dtm;
	
	public CheckboxListener(FillFormDialog fillFormDialog, DefaultTableModel dtm) {
		this.fillFormDialog = fillFormDialog;
		this.dtm = dtm;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		CustomCheckbox customCheckbox = (CustomCheckbox)e.getSource();
		if("全选".equals(customCheckbox.getText())) {
			for (int i = 0; i < dtm.getRowCount() - 1; i++) {
				CustomCheckbox temp = (CustomCheckbox)dtm.getValueAt(i, 0);
				temp.setSelected(customCheckbox.isSelected());
				dtm.setValueAt(temp, i, 0);
	        }
			fillFormDialog.updateHours();
		}
		else {
			fillFormDialog.updateHours();
		}
	}
}